﻿for($i=1;$i -le 100;$i++) {

#$fileSave="d:\log\test"+(Get-Date).ToString("yyyy-MM-dd_HH-mm-ss")+".txt"  #wrong
$fileSave="d:\log\test\"+(Get-Date).ToString("yyyy-MM-dd_HH-mm-ss")+".txt"

if (!(Test-Path "d:\log\test")) {
    # New-Item -ItemType Directory -Path $fileSave -Force
    New-Item -ItemType Directory -Path "d:\log\test" -Force
}

    $win=0
    for ($j=1;$j -le 100;$j++) {
        #sleep(1)
        #$win=0

        $punch1 = Get-Random -Minimum 1 -Maximum 3
        $punch2 = Get-Random -Minimum 1 -Maximum 3
        $outStr=""

        if ($punch1 -eq $punch2) {
            $outStr="The "+$j+" time, draw match."
        } elseif ($punch1 -lt $punch2) {
            $outStr = "The "+$j+" time, punch2 wins."
        } else {
            $win++
            $outStr = "The "+$j+" time, punch1 wins."
        }
        
        $outStr |Out-File -FilePath $fileSave -Encoding utf8 -Append
    }
    #sleep(1)
    $winrate = "$win" + "%"
    "punch1 win rate is "+$winrate |Out-File -FilePath $fileSave -Encoding utf8 -Append
    $win=0
}

